'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url client/user/kh/walletOverview 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------
    let dbName = 'uni-id-users'
    let walletData = await vk.baseDao.findById({
      dbName,
      id: uid
    });
    walletData.total_revenue = walletData.total_revenue || 0
    walletData.balance = walletData.balance || 0
    
    let { todayStart, todayEnd } = vk.pubfn.getCommonTime();
    let { rows } = await vk.baseDao.select({
      dbName: 'avatar-earning-detail',
      getCount:false, // 是否需要同时查询满足条件的记录总数量，默认false
      getMain:false, // 是否只返回rows数据，默认false
      pageIndex:1, // 当前第几页
      pageSize:1000, // 每页条数
      whereJson:{
        user_id: uid,
        created_at: _.gte(todayStart).lte(todayEnd)  
      }
    });
    
    let todayIncome = rows.reduce((prev, cur)=>{
      return prev + cur.amount
     }, 0)
    walletData.todayIncome = todayIncome
    res.data = walletData

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
